{% extends 'admin/base.html'%}

{% block body%}
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-toolbar clearfix">
                    <!-- <form class="pull-right search-bar" method="get" action="{{url_for('admin.index')}}" role="form">
                        <div class="input-group">
                            <input autocomplete="off" type="text" name="keywords" class="form-control" placeholder="请输入关键词...">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-default" type="button">搜索</button>
                            </span>
                        </div>
                    </form> -->
                    <div class="toolbar-btn-action">
                        {%if current_user.have_permission('menu.add')%}<a class="btn btn-primary m-r-5"
                            href="{{url_for('menu.add')}}"><i class="mdi mdi-plus"></i>
                            新增</a>{% endif%}
                        {%if current_user.have_permission('menu.delete_op')%}<a class="btn btn-danger"
                            href="javascript:void(0)" onclick="doDeleteAll()"><i class="mdi mdi-window-close"></i>
                            删除</a>{% endif%}
                    </div>
                </div>
                <div class="card-body">

                    {% for message in get_flashed_messages() %}
                    <div class="alert alert-danger alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                                aria-hidden="true">×</span></button>
                        {{ message }}
                    </div>
                    {% endfor %}

                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>
                                        <label class="lyear-checkbox checkbox-primary">
                                            <input type="checkbox" id="check-all"><span></span>
                                        </label>
                                    </th>
                                    <th>ID</th>
                                    <th>菜单名称</th>
                                    <th>URL地址</th>
                                    <th>排序</th>
                                    <th>是否菜单</th>
                                    <th>状态</th>
                                    <th>修改时间</th>
                                    <th width="130">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for a in menus %}
                                <tr>
                                    <td>
                                        <label class="lyear-checkbox checkbox-primary">
                                            <input type="checkbox" name="ids[]" value="{{a.id}}"><span></span>
                                        </label>
                                    </td>
                                    <td>{{a.id}}</td>
                                    <td>{{a.level | my_repeat}}{{a.name}}</td>
                                    <td>{{a.url}}</td>
                                    <td>{{a.sort}}</td>
                                    <td>
                                        {% if a.is_menu==1%}
                                        <font class="text-success">是</font>
                                        {%else%}
                                        <font class="text-danger">否</font>
                                        {% endif%}
                                    </td>
                                    <td>
                                        {% if a.status==1%}
                                        <font class="text-success">启用</font>
                                        {%else%}
                                        <font class="text-danger">禁用</font>
                                        {% endif%}
                                    </td>
                                    <td>{{a.update_time}}</td>
                                    <td>
                                        <div class="btn-group">
                                            {%if current_user.have_permission('menu.edit')%}<a
                                                class="btn btn-primary btn-xs"
                                                href="{{url_for('menu.edit', id=a.id)}}"><i
                                                    class="mdi mdi-pencil"></i>
                                                编辑</a>
                                            {% endif%}
                                            {%if current_user.have_permission('menu.delete_op')%}
                                            <a class="btn btn-xs btn-danger"
                                                href="javascript:void(0)" onclick="delete_op('{{a.id}}')"><i
                                                    class="mdi mdi-window-close"></i>删除</a>
                                            {% endif%}
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock%}

{%block foot%}
<script type="text/javascript">
    function getSelected() {
        var checkbox = $("tbody .lyear-checkbox > input")
        var ids = []
        checkbox.each(function (k, v) {
            if ($(this).is(":checked")) {
                ids.push($(this).val())
            }
        })
        return ids.join(",")
    }

    function doDeleteAll() {
        var ids = getSelected()
        delete_op(ids)
    }

    function delete_op(ids) {
        $.confirm({
            title: '警告',
            content: '您确定要删除吗？',
            type: 'orange',
            typeAnimated: true,
            buttons: {
                tryAgain: {
                    text: '确定',
                    btnClass: 'btn-red',
                    action: function () {
                        window.location.href = "{{url_for('menu.delete_op')}}?id=" + ids
                    }
                },
                close: {
                    text: '关闭'
                }
            }
        });
    }
</script>
{% endblock%}